function sendJsonPost(url, inputPara, successMethod, errorMethod, async, params) {
    $.ajax({
        url: url,
        type: "post",
        data: inputPara,
        timeout: ajaxCommonTimeout,
        async: async,
        dataType: "json",
        contentType: "application/x-www-form-urlencoded; charset=utf-8",
        error: function (response, status, xhr) {
            if (params == null) {
                errorMethod(status);
            } else {
                errorMethod(status, params);
            }
        },
        success: function (json) {
            if (params == null) {
                successMethod(json);
            } else {
                successMethod(json, params);
            }
        }
    });
}

// call data sync
function callJsonDataBySync(url, inputPara, successMethod, errorMethod) {
    sendJsonPost(url, inputPara, successMethod, errorMethod, false, null);
}

// call data sync with common error method
function callJsonDataBySync(url, inputPara, successMethod) {
    sendJsonPost(url, inputPara, successMethod, commonErrorMethod, false, null);
}

// call data sync with params
function callJsonDataBySyncWithParam(url, inputPara, successMethod, errorMethod, params) {
    sendJsonPost(url, inputPara, successMethod, errorMethod, false, params);
}

// call data async
function callJsonDataWithMethod(url, inputPara, successMethod, errorMethod) {
    sendJsonPost(url, inputPara, successMethod, errorMethod, true, null);
}

// call data async with common error method
function callJsonData(url, inputPara, successMethod) {
    sendJsonPost(url, inputPara, successMethod, commonErrorMethod, true, null);
}

// call data async with params
function callJsonDataWithParam(url, inputPara, successMethod, params) {
    sendJsonPost(url, inputPara, successMethod, commonErrorMethod, true, params);
}

function commonErrorMethod() {
    popalert({
        "content": "系统忙，请稍后重试！",
        "icon": "warning",
        "ok": null,
        "close": null,
        "okVal": "确定",
        "cancel": false
    });
}

/**
 * 计算缩放比例
 *
 * @param innerWidth
 *            要放置元素的宽
 * @param innerHeight
 *            要放置元素的高
 * @param outerWidth
 *            容器元素的宽
 * @param outerHeight
 *            容器元素的高
 * @returns {Number} 比例
 */
function calcRate(innerWidth, innerHeight, outerWidth, outerHeight) {
    var retRate = 1;
    if (innerHeight !== outerHeight && innerWidth !== outerWidth) {
        // 只要宽or高大于,则需要缩放
        if (innerWidth > outerWidth && innerHeight > outerHeight
            || innerWidth < outerWidth && innerHeight < outerHeight) {
            // 均大于,则取取宽度比、高度比的更小者, 反之放大获取最小比例
            var rate_temp_1 = outerWidth / innerWidth;
            var rate_temp_2 = outerHeight / innerHeight;
            if (rate_temp_1 > rate_temp_2) {
                retRate = rate_temp_2;
            } else {
                retRate = rate_temp_1;
            }
        } else if (innerWidth > outerWidth) {
            // 只有宽大于,则直接取比率
            retRate = outerWidth / innerWidth;
        } else {
            // 只有高大于,则直接取比率
            retRate = outerHeight / innerHeight;
        }
    }
    return retRate;
}

/**
 * javascript Map (key - value)
 */
function JsMap() {
    this.map = new Object();
    this.length = 0;

    this.size = function () {
        return this.length;
    };

    this.put = function (key, value) {

        if (!this.map['_' + key]) {
            ++this.length;
        }

        this.map['_' + key] = value;

    };

    this.remove = function (key) {

        if (this.map['_' + key]) {

            --this.length;
            return delete this.map['_' + key];
        } else {
            return false;
        }
    };

    this.containsKey = function (key) {

        return this.map['_' + key] ? true : false;

    };

    this.get = function (key) {

        return this.map['_' + key] ? this.map['_' + key] : null;

    };

    this.inspect = function () {
        var str = '';

        for (var each in this.map) {
            str += '\n' + each + '  Value:' + this.map[each];
        }

        return str;
    };

    this.keys = function () {
        var keys = new Array();

        for (var each in this.map) {
            keys.push(each);
        }

        return keys;
    };

    this.values = function () {
        var values = new Array();

        for (var each in this.map) {
            values.push(this.map[each]);
        }

        return values;
    };
}